package com.fh.shop.admin.book.controller;

import com.fh.shop.admin.book.biz.IBookService;
import com.fh.shop.admin.book.po.Book;
import com.fh.shop.admin.common.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

@RestController
@RequestMapping("/api/books")
@Api(tags = "图书控制器类")
public class BookController {

    @Resource(name = "bookService")
    private IBookService bookService;

    @PostMapping
    @ApiOperation("添加图书")
    public ServerResponse addBook(Book book) {
        return bookService.addBook(book);
    }

    @DeleteMapping
    @ApiOperation("批量删除图书")
    public ServerResponse deleteBatch(String ids) {
        return bookService.deleteBatch(ids);
    }




    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public ServerResponse findBook(@PathVariable Long id) {
        Book book = new Book();
        if (id.longValue() == 1) {
            book.setBookName("三国");
            book.setBookPrice(new BigDecimal(89.96));
        } else {
            book.setBookName("xiyou");
            book.setBookPrice(new BigDecimal(99.96));
        }
        return ServerResponse.success(book);
    }

}
